#############################################################################
# $Id$
#
# Copyright (c) 2012 Regents of the University of California
#   <bkpark@ucdavis.edu>
# Copyright (c) 2009 Sandro Santilli <strk@keybit.net>
#
# This is free software; you can redistribute and/or modify it under
# the terms of the GNU General Public Licence. See the COPYING file.
#
#############################################################################

# Filenames with extension as determined by the OS
TESTAPI=testapi@EXESUFFIX@
TESTWKB=testwkb@EXESUFFIX@

RT_CORE=../../rt_core

LIBLWGEOM_LDFLAGS=../../../liblwgeom/.libs/liblwgeom.a
LIBLWGEOM_CFLAGS=-I../../../liblwgeom
LIBGDAL_CFLAGS=@LIBGDAL_CFLAGS@
LIBGDAL_LDFLAGS=@LIBGDAL_LDFLAGS@
PROJ_CFLAGS=@PROJ_CPPFLAGS@
GEOS_CFLAGS=@GEOS_CPPFLAGS@
GEOS_LDFLAGS=@GEOS_LDFLAGS@ -lgeos_c

RTCORE_CFLAGS=-I$(RT_CORE)
RTCORE_LDFLAGS=$(RT_CORE)/librtcore.a

CC=@CC@
CFLAGS = \
	@CFLAGS@ @PICFLAGS@ @WARNFLAGS@ \
	$(RTCORE_CFLAGS) \
	$(LIBLWGEOM_CFLAGS) \
	$(PROJ_CFLAGS) \
	$(LIBGDAL_CFLAGS) \
	$(GEOS_CFLAGS)

LDFLAGS = \
	$(RTCORE_LDFLAGS) \
	$(LIBLWGEOM_LDFLAGS) \
	$(LIBGDAL_LDFLAGS) \
	$(GEOS_LDFLAGS) \
	-lm \
       
all: $(TESTAPI) $(TESTWKB)

check: $(RT_CORE)/librtcore.a $(TESTAPI) $(TESTWKB)
	./testapi
	./testwkb

testapi.o: testapi.c
	$(CC) $(CFLAGS) -c $<

$(TESTAPI): testapi.o $(RT_CORE)/librtcore.a
	$(LIBTOOL) --mode=link $(CC) $(CFLAGS) $^ $(LDFLAGS) -o $@

testwkb.o: testwkb.c
	$(CC) $(CFLAGS) -c $<

$(TESTWKB): testwkb.o $(RT_CORE)/librtcore.a
	$(LIBTOOL) --mode=link $(CC) $(CFLAGS) $^ $(LDFLAGS) -o $@

$(RT_CORE)/librtcore.a:
	$(MAKE) -C ../../rt_core

clean:
	rm -rf .libs
	rm -f *.o $(TESTAPI) $(TESTWKB)

distclean: clean
	rm -f Makefile
